#!/bin/sh

echo "Needs to be updated, sorry."
exit

PATH_ORIG="$PATH"
PATH=".:$PATH"
export PATH

#Freebsd wisely appends verion so prog so check for those
AM=`which automake15`
AC=`which autoconf253`
AH=`which autoheader253`
AL=`which aclocal15`
LT=`which libtool15`
LZ=`which libtoolize15`

if test "x$AM" = "x"; then
	AM=`which automake`
fi
if test "x$AC" = "x"; then
	AM=`which autoconf`
fi
if test "x$AH" = "x"; then
	AH=`which autoheader`
fi
if test "x$AL" = "x"; then
	AL=`which aclocal`
fi
if test "x$LT" = "x"; then
	LT=`which libtool`
fi
if test "x$LZ" = "x"; then
	LZ=`which libtoolize`
else
	echo "linking $LZ to ./libtoolize so libtool15 will find it."
	ln -s $LZ libtoolize
fi


AM_V=`$AM --version|head -1|awk '{ print $4; }'`
AC_V=`$AC --version|head -1|awk '{ print $4; }'`
AH_V=`$AH --version|head -1|awk '{ print $4; }'`
AL_V=`$AL --version|head -1|awk '{ print $4; }'`
LT_V=`$LT --version|head -1|awk '{ print $4; }'`
LZ_V=`$LT --version|head -1|awk '{ print $4; }'`


gnutools_test() {
    echo "automake: $AM_V"
    echo "autoconf: $AC_V"
    echo "autoheader: $AH_V"
    echo "aclocal: $AL_V"
    echo "libtool: $LT_V"
    echo "libtoolize: $LZ_V"
    if test "$AM_V" = "1.5" \
	-a "$AC_V" = "2.53" \
	-a "$AH_V" = "2.53" \
	-a "$AL_V" = "1.5" ; then
	echo "Gnutools version test passed"
	echo "  If you get shell syntax errors when libtool compiles,"
	echo "  most likely you have 1.5 AND and older libtool installed."
	echo "  Deinstall all libtool packages and reinstall 1.5."
	LIBTOOL13=`which libtool13`
	if test "x$LIBTOOL13" != "x"; then
	    echo "WARNING: you appear to have libtool 1.3.x ($LIBTOOL13) installed !"
	    echo "This can cause all sorts of libtool problems."
	fi
	return 0;
    else
	echo "Gnutools version test failed: do not run maintenance on this machine"
	return 1;
    fi
}

cleanup() {
    PATH="$PATH_ORIG"
    export PATH
    unlink ./libtoolize
}

case $1 in
-make|--make)
	gnutools_test && \
	$AM -a && \
	  ./configure && \
	  make
	cleanup
	;;
-test|--test)
	gnutools_test
	cleanup
	;;
-build|--build)	
	gnutools_test && \
	$AL && \
	  $AC && \
	  $AH && \
	  $AM -a && \
	  ./configure && \
	  make
	cleanup
	;;
*)	
	gnutools_test && \
	$AL && \
	  $AC && \
	  $AH && \
	  $AM -a
	cleanup
	;;
esac
